package com.cv.platform.dal.mapper.favourite;

import com.cv.framework.common.pojo.PageResult;
import com.cv.framework.mybatis.core.mapper.BaseMapperX;
import com.cv.framework.mybatis.core.query.MPJLambdaWrapperX;
import com.cv.framework.security.core.utils.SecurityFrameworkUtil;
import com.cv.platform.controller.platform.favourite.vo.CvVideoFavouriteRespVO;
import com.cv.platform.controller.platform.favourite.vo.CvVideoFavouriteReqVO;
import com.cv.platform.dal.dataobject.favourite.CvVideoFavouriteDO;
import com.cv.platform.dal.dataobject.video.CvVideoDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 视频收藏数据层
 *
 * @author Charles_XDXD
 */
@Mapper
public interface CvVideoFavouriteMapper extends BaseMapperX<CvVideoFavouriteDO> {

    default PageResult<CvVideoFavouriteRespVO> selectPage(CvVideoFavouriteReqVO reqVO) {
        return selectJoinPage(reqVO, CvVideoFavouriteRespVO.class, new MPJLambdaWrapperX<CvVideoFavouriteDO>()
                .selectAll(CvVideoFavouriteDO.class)
                .eq(CvVideoFavouriteDO::getUserId, SecurityFrameworkUtil.getLoginUserId())
                .leftJoin(CvVideoDO.class, CvVideoDO::getId, CvVideoFavouriteDO::getVideoId)
                .likeIfExists(CvVideoDO::getTitle, reqVO.getTitle())
                .selectAs(CvVideoDO::getThumbnail, CvVideoFavouriteRespVO::getThumbnail)
                .selectAs(CvVideoDO::getTitle, CvVideoFavouriteRespVO::getTitle)
                .selectAs(CvVideoDO::getViewCount, CvVideoFavouriteRespVO::getViewCount)
                .selectAs(CvVideoDO::getCommentCount, CvVideoFavouriteRespVO::getCommentCount)
                .selectAs(CvVideoDO::getCreateTime, CvVideoFavouriteRespVO::getPublishTime)
                .orderByDesc(CvVideoFavouriteDO::getCreateTime)
        );
    }

}
